/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisgea.controller;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import sisgea.bean.SoloBean;
import sisgea.conexaobd.ConexaoPost;

/**
 *
 * @author Lau
 */
public class SoloControl {
    
    
    PreparedStatement pstm;
    ResultSet rs;
    String consultaSolo = "SELECT * FROM tblSolo WHERE Solo LIKE ?";
    String cadastraSolo = "INSERT INTO tblSolo (Empresa, Solo, DescSolo, Taxonomia, Observacao, UsuarioQueIncluiu, DataInclusao, DataUltimaAtualizacao) VALUES (?,?,?,?,?,?,?,?)";
    
   
    public SoloControl(){
    }
    
    public void cadastrarSolo(SoloBean solo){
        
        try{
            ConexaoPost conexao = new ConexaoPost();
            pstm = (PreparedStatement) conexao.conectar().prepareStatement(cadastraSolo);
            pstm.setString(1, solo.getEmpresa());
            pstm.setString(2, solo.getSolo());
            pstm.setString(3, solo.getDescsolo());
            pstm.setString(4, solo.getTaxonomia());
            pstm.setString(5, solo.getObservacao());
            pstm.setString(6, solo.getUsuarioqueincluiu());
            pstm.setString(7, solo.getDatainclusao());
            pstm.setString(8, solo.getDataultimaatualizacao());
            
            pstm.executeUpdate();
            
            conexao.desconectar();
            
        }
        
        
        catch (Exception e){
            e.printStackTrace();
        }
    }
    
    
    
    public List<SoloBean> SoloExperimentos(String solo){
        List<SoloBean> solos = null;
    
        try{
            ConexaoPost conecxao = new ConexaoPost();
            pstm = (PreparedStatement) conecxao.conectar().prepareStatement(consultaSolo);
            pstm.setString(1, solo);
            rs = pstm.executeQuery();
            SoloBean sol;
            while (rs.next()){
                sol = new SoloBean();
               
                sol.setEmpresa(rs.getString("empresa"));
                sol.setSolo(rs.getString("solo"));
                sol.setDescsolo(rs.getString("descsolo"));
                sol.setTaxonomia(rs.getString("taxonomia"));
                sol.setObservacao(rs.getString("observacao"));
                sol.setUsuarioqueincluiu(rs.getString("usuarioqueincluiu"));
                sol.setDatainclusao(rs.getString("datainclusao"));
                sol.setDataultimaatualizacao(rs.getString("dataultimaatualizacao"));

                solos.add(sol);
               
            }
            
            conecxao.desconectar();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return solos;
        
    }
    
}
